﻿package ua.mihaylenko.cardsplugin.colorpicker{
	/**
	Creates a box movieclip of selected color. When the color selection is 
	updated, it updates the color of movieclip.
	It displays the selected color visually.
	
	
	@author Sharwan Kami <sharwan@gmail.com>
	@version 1.0
	@history 2009-05-10
	
	* 
	* This file is part of E-Card plugin, from zetaprints.com
	* 
	
	@usage
	Activate with:
		<code>
			//create instance of color box
			colorBox=new ColorBox();
			colorBox.color=0x00ff00;
			colorBox.x=30;
			colorBox.y=80;
			addChild(colorBox);
		</code>
	
	*/
	import flash.display.MovieClip;
	import flash.geom.ColorTransform;
	
	public class ColorBox extends MovieClip{
		private var boxWidth:Number=50;//width of the color box
		private var boxHeight:Number=50;//height of the color box
		private var boxColor:uint=0xff0000;//box color (default is white)
		private var box:MovieClip;//movie clip to display color
		
		/**
			Constructor
		*/
		function ColorBox(){
			init();
		}
		
		/**
		creates the bordered box and adds
		*/
		public function init():void{
			///draw box
			this.graphics.lineStyle(1,0x000000,1);
			this.graphics.drawRect(0,0,boxWidth+1,boxHeight+1);
			
			box=new MovieClip();
			box.graphics.beginFill(boxColor);
			box.graphics.drawRect(1,1,boxWidth,boxHeight);
			box.graphics.endFill();			
			addChild(box);
		}
		
		/**
		called from other classes to update the box color
		*/
		private function updateColor():void{
			//update the box color based on selected color
			var newColorTransform:ColorTransform = box.transform.colorTransform;
			newColorTransform.color = uint("0x"+ZColor.getRGB(boxColor));
			box.transform.colorTransform = newColorTransform;
		}
		
		
		/**
		sets the box color with new value and updates the color of box
		*/
		public function set color(value:uint):void{
			boxColor=value;
			updateColor();
		}
		
		/**
		returns the box color
		*/
		public function get color():uint{
			return boxColor;
		}	
		
	}
}